package kcms.common.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import kcms.common.dao.CommonDao;
import kcms.db.Token;
import kcms.db.ViewAssignScore;
import kcms.db.ViewMessage;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

@Repository
public class CommonDaoImpl extends HibernateDaoSupport implements CommonDao{
	@Resource
	private SessionFactory sessionFactory;
	@Resource
	public void setMySessionFactory(SessionFactory sessionFactory) {
		super.setSessionFactory(sessionFactory);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ViewMessage> getMessagesSize(String sid) {
		// TODO Auto-generated method stub
		String hql="from ViewMessage where status=? and sid=?";
		return(List<ViewMessage>)this.getHibernateTemplate().find(hql,true,sid);
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<ViewAssignScore> getAssignMessagesSize(String sid) {
		// TODO Auto-generated method stub
		String hql="from ViewAssignScore where status=? and sid=?";
		return(List<ViewAssignScore>)this.getHibernateTemplate().find(hql,true,sid);
		
	}
	public void saveToken(Token token){
		this.getHibernateTemplate().save(token);
	}
	public Token getTokenObj(String token){
		if(this.getHibernateTemplate().find("from Token t where t.token=?", token).isEmpty())
			return null;
		else
			return (Token) this.getHibernateTemplate().find("from Token t where t.token=?", token).get(0);
	}
	public void delTokenObj(Token temptoken){
		this.getHibernateTemplate().delete(temptoken);
	}
}
